<?php
$tbCategory = new Model_DbTable_ProductCategory();
$category = $this->category_all;

$count = count($category);
$w = $count ? floor(932/($count+2))-2 : 155;
$s = 'style="width:'. $w .'px"';
$s2 = 'style="width:'. ($w - 8).'px"';


$controller = $this->app_controller;
$action     = $this->app_action;

$categoryId       = null;
$parentCategoryId = null;
if($controller == 'product') {
    $categoryActive   = $this->category;
    $categoryId       = $categoryActive['id'];
    $parentCategoryId = $categoryActive['parent_id'];
}

$classActive = 'class="menu-active"';
?>
<ul id="menu-container">
    <li class="menu-item-first"><a href="/trang-chu.html" <?php echo $s ?> <?php if($controller == 'home' && $action == 'index') echo $classActive ?>>Trang chủ</a></li>
    <!-- li><a href="/san-pham-moi.html" <?php echo $s ?> <?php if($controller == 'product' && $action == 'new') echo $classActive ?>>Sản phẩm mới</a></li-->
    <?php if($category): ?>
    <?php foreach ($category as $key => $value): ?>
    <li>
        <a href="/san-pham/<?php echo $this->routeUrl($value['title']) . '-' . $value['id'] .'.html' ?>" <?php echo $s ?> <?php if($value['id'] == $categoryId || $value['id'] == $parentCategoryId) echo 'class="menu-active"' ?>><?php echo $value['title'] ?></a>

        <?php $childCategory = $tbCategory->listChildCategory($value['id']); ?>
        <?php if($childCategory): ?>
            <ul class="submenu">
                <?php foreach ($childCategory as $val): ?>
                <li><a href="/san-pham/<?php echo $this->routeUrl($val['title']) . '-' . $val['id'] .'.html' ?>" <?php echo $s2 ?>><?php echo $val['title'] ?></a></li>
                <?php endforeach; ?>
            </ul>
        <?php endif; ?>
    </li>
    <?php endforeach; ?>
    <?php endif; ?>
    <li style="background-image:none"><a href="/khuyen-mai.html" <?php echo $s ?> <?php if($controller == 'product' && $action == 'sale-off') echo $classActive ?>>sale off</a></li>
</ul>
<div class="clear"></div>